package com.xm.util;

import java.util.List;

/**
 * @author xie'lin'feng
 * @date 2020-08-04-18:35
 * @description 分页工具类
 */
public class PageBean<E> {
    /**数据*/
    private List<E> data;
    /**总记录数*/
    private Integer count;
    /**页码*/
    private Integer pageIndex;
    /**总页数*/
    private Integer totalPage;
    /**首页*/
    private Integer headPage;
    /**尾页*/
    private Integer footPage;
    /**上一页*/
    private Integer prevPage;
    /**下一页*/
    private Integer nextPage;
    /**每页条数*/
    private Integer pageCount;
    /**当前页*/
    private Integer currPage;

    public PageBean(List<E> data, Integer count, Integer pageIndex,Integer pageCount) {
        this.data = data;
        this.count = count;
        this.pageIndex = pageIndex;
        this.pageCount = pageCount;
    }

    public PageBean() {
    }

    public List<E> getData() {
        return data;
    }

    public void setData(List<E> data) {
        this.data = data;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }
    //总页数
    public Integer getTotalPage() {
        double sum = this.getCount();
        double num = this.getPageCount();
        return (int)Math.ceil(sum/num);
    }
    //首页
    public Integer getHeadPage() {
        return 1;
    }
    //尾页
    public Integer getFootPage() {
        return this.getTotalPage();
    }
    //上一页
    public Integer getPrevPage() {
        if (this.getPageIndex()-1<=this.getHeadPage()){
            return this.getHeadPage();
        }
        return getPageIndex()-1;
    }
    //下一页
    public Integer getNextPage() {
        if (this.getPageIndex()+1>this.getFootPage()){
            return getFootPage();
        }
        return getPageIndex()+1;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getCurrPage() {
        return currPage;
    }

    public void setCurrPage(Integer currPage) {
        this.currPage = currPage;
    }
}
